package cn.nexttec.noteplayer.databases

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import cn.nexttec.noteplayer.databases.converters.DateConverter
import cn.nexttec.noteplayer.databases.dao.NoteDao
import cn.nexttec.noteplayer.databases.dao.PlayRecordDao
import cn.nexttec.noteplayer.databases.dao.VideoFileDao
import cn.nexttec.noteplayer.models.NoteFile
import cn.nexttec.noteplayer.models.PlayRecord
import cn.nexttec.noteplayer.models.VideoFileInfo

@Database(entities = [VideoFileInfo::class, PlayRecord::class, NoteFile::class], version = 1, exportSchema = true)
@TypeConverters(DateConverter::class)
abstract class NoteDatabase : RoomDatabase() {
    abstract fun getVideoFileDao(): VideoFileDao
    abstract fun getPlayRecordDao(): PlayRecordDao
    abstract fun getNoteDao(): NoteDao

    companion object {
        fun get(context: Context): NoteDatabase {
            return Room.databaseBuilder(context, NoteDatabase::class.java, context.packageName)
                .addMigrations()
                .build()
        }
    }

    val MIGRATION_1_2 = object : Migration(1, 2) {
        override fun migrate(database: SupportSQLiteDatabase) {
            database.execSQL("")
        }
    }
}